package my.edu.model.information.service;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import my.edu.common.constant.MessageConstant;
import my.edu.common.exception.CanNotFoundException;
import my.edu.model.information.entity.dto.AddressSaveDTO;
import org.springframework.stereotype.Service;
import my.edu.model.information.entity.Address;
import my.edu.model.information.mapper.AddressMapper;

import java.util.Optional;

@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements IAddressService {

    @Override
    public void savenew(AddressSaveDTO addressSaveDTO) {
        Address address = BeanUtil.copyProperties(addressSaveDTO, Address.class);
        long count = count();
//        address.setAddressNo(String.format("D%04d", count + 1));
        save(address);
    }

    @Override
    public void updateByDTO(AddressSaveDTO addressSaveDTO) {
        Address address = BeanUtil.copyProperties(addressSaveDTO, Address.class);
        updateById(address);
//        lambdaUpdate()
//                .eq(Address::getAddressNo, address.getAddressNo())
//                .update(address);
    }

//    @Override
//    public Address getByNo(String no) {
//        Optional<Address> address = lambdaQuery()
//                .eq(Address::getAddressNo, no)
//                .oneOpt();
//        if (address.isEmpty()){
//            throw new CanNotFoundException(MessageConstant.CAN_NOT_FOUND);
//        }
//        return address.get();
//    }

}
